package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.entity.Post;
import com.tenement.enums.RespBusiness;
import com.tenement.service.PostService;
import com.tenement.vo.QueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/post")
@RequiredArgsConstructor
@Validated
@Api(tags = "岗位管理")
public class PostController {

    private final PostService postService;


    @ApiOperation("操作数据")
    @PutMapping("operator")
    public Axios operator(@RequestBody @Validated Post post) {
        return postService.saveOrUpdate(post) ? Axios.success("成功") : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation("根据id获取岗位")
    @GetMapping("oneId/{id}")
    public Axios oneId(@PathVariable Serializable id) {
        return Axios.success(postService.getById(id));
    }

    @ApiOperation("获取岗位列表")
    @PostMapping("list")
    public Axios list(@RequestBody QueryVo queryVo) {
        return Axios.success(postService.list(queryVo));
    }


    @ApiOperation("获取所有岗位列表")
    @GetMapping("listAll")
    public Axios listAll() {
        return Axios.success(postService.list());
    }

    @ApiOperation("删除岗位")
    @DeleteMapping("delete")
    public Axios delete(@RequestBody List<Long> id) {
        return postService.removeByIds(id) ? Axios.success("成功") : Axios.error(RespBusiness.FAIL);
    }

}
